/*

Please compile using  gcc -g Example.c -lpthread -std=c99 -O
 */
 
#include <time.h>
#include <math.h>
#include <stdlib.h>
#include <time.h> 
#include <stdio.h>
#include <pthread.h>
#define SIZE    5

int  array[SIZE];
void max(int  *);
void *min(int  *);
void mean(int  *);

void randomfill(int  *);
int t1 = 0, t2 = 0, t3=0;
 
main()
{
clock_t tic = clock();
randomfill(&array);
printf("\nRandomly Generated array(5 integers) in between 0 and 1000 is \n");
for(int i=0; i<SIZE; i++)
printf( "%d   ",array[i]);
  pthread_t       thread1,thread2,thread3;
 
  pthread_create(&thread1,
         NULL,
         max,
         (void *)t1);
 
  pthread_create(&thread2,
         NULL,
         (void *) &min,
         (void *)t2);
  pthread_create(&thread3,
         NULL,
         (void *) &mean,
         (void *)t3);
void *result;
  pthread_join(thread1, &result);
  pthread_join(thread2, &result);
  pthread_join(thread3, &result);
clock_t toc = clock();
printf("\nAnd Elapsed: %f seconds \n", (double)(toc - tic) / CLOCKS_PER_SEC);
}
 
void max(int  *array)
{
int maxi=array[0];
for (int i=0;i<SIZE;i++)
{
{
if(maxi<array[i])
maxi=array[i];
}
printf("\nNow maxi= %d",maxi);
}
printf("\nThe maximum of the given array is %d :",maxi);
}
 
void *min(int  *array)
{
int mi=array[0];
for (int i=0;i<SIZE;i++)
{
if(mi>array[i])
mi=array[i];
printf("\nNow mi = %d",mi);
}
printf("\nThe minimum  of the given array is %d :",mi);
}

void mean(int  *array)
{
 int mea=0,mea1=0;
for (int i=0;i<SIZE;i++)
{
mea=mea+array[i];
mea1=mea/5;
printf("\nNow sum(mea) = %d",mea);
printf("\nNow i m running mean %d",i);
}
printf("\nThe mean  of the given array is %d ",mea1);
}
void randomfill(int  *array)
{
 srand((unsigned)time(0));
  for(int i=0; i<SIZE; i++)
  array[i] = (rand()%1000)+0;
}
